package cn.ingrun.utils.controller;

import cn.ingrun.utils.auth.AuthServer;
import cn.ingrun.utils.auth.LoginAuth;
import cn.ingrun.utils.controller.mapper.UserMapper;
import cn.ingrun.utils.responseUtil.ResponseUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@Api( tags = "hello 模块")
@RestController
public class HelloController {


    private AuthServer authServer;

    private UserMapper userMapper;

    @Autowired
    public void setAuthServer(AuthServer authServer) {
        this.authServer = authServer;
    }

    @Autowired
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @ApiOperation("获取用户信息")
    @LoginAuth
    @GetMapping("/get/{id}")
    public ResponseUtils hello( @ApiParam("用户ID") @PathVariable String id){
        return ResponseUtils.success(userMapper.getUser(Integer.parseInt(id)));
    }

    @ApiOperation("用户登录")
    @GetMapping("/login/{id}")
    public ResponseUtils login(@ApiParam("用户ID") @PathVariable String id){
        return ResponseUtils.success("success",authServer.login(id, 20 * 60));
    }

    @ApiOperation("用户注销登录")
    @GetMapping("/logout/{id}")
    public ResponseUtils logout(@ApiParam("用户ID") @PathVariable String id){
        return ResponseUtils.auto(authServer.logout());
    }

    @GetMapping("/getSum/{id}")
    public ResponseUtils getSum(@PathVariable String id){
        return ResponseUtils.success(userMapper.getSum(id));
    }


}
